package com.baidu.st.fe.spllot.dto;

import java.util.HashMap;
import java.util.Map;

public class TokenEntry {
	public static final TokenEntry EOF = new TokenEntry();

	private String tokenSrcID;
	private int beginLine;
	private int index;
	private int identifier;

	private final static Map<String, Integer> Tokens = new HashMap<String, Integer>();
	private static int TokenCount = 0;

	private TokenEntry() {
		this.identifier = 0;
		this.tokenSrcID = "EOFMaker";
	}

	public TokenEntry(String image, String tokenSrcID, int beginLine) {
		Integer i = Tokens.get(image);
		if (i == null) {
			i = Tokens.size() + 1;
			Tokens.put(image, i);
		}
		this.identifier = i.intValue();
		this.tokenSrcID = tokenSrcID;
		this.beginLine = beginLine;
		this.index = TokenCount++;
	}

	public String getTokenSrcID() {
		return tokenSrcID;
	}

	public void setTokenSrcID(String tokenSrcID) {
		this.tokenSrcID = tokenSrcID;
	}

	public int getBeginLine() {
		return beginLine;
	}

	public void setBeginLine(int beginLine) {
		this.beginLine = beginLine;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public int getIdentifier() {
		return identifier;
	}

	public void setIdentifier(int identifier) {
		this.identifier = identifier;
	}

	public static int getTokenCount() {
		return TokenCount;
	}

	public static void setTokenCount(int tokenCount) {
		TokenCount = tokenCount;
	}

	public static TokenEntry getEof() {
		TokenCount++;
		return EOF;
	}

	public static Map<String, Integer> getTokens() {
		return Tokens;
	}

	public static void clearImage() {
		Tokens.clear();
		TokenCount = 0;
	}
}
